package com.lkei.controller;

import com.alibaba.fastjson.JSONObject;
import com.lkei.entity.GroupMessage;
import com.lkei.dto.Result;
import com.lkei.service.GroupMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("groupMessage")
public class groupMessageController {

    @Autowired
    private GroupMessageService groupMessageService;

    @CrossOrigin
    @RequestMapping("findGroupMessage")
    private Result findGroupMessageByName(@RequestBody String data){
        // 将接收到的Json解析为map
        JSONObject jsonObject = JSONObject.parseObject(data);
        Map<String, Object> map = new HashMap<>();
        map.putAll(jsonObject);
        String groupName=map.get("groupName").toString();

        List<GroupMessage> gm=groupMessageService.findGroupMessageByName(groupName);
        return Result.SUCCESS.setNewData(gm);
    }
    @CrossOrigin
    @RequestMapping("findAll")
    public Result findAll(){
        List<GroupMessage> groupMessages=groupMessageService.findAll();
        return Result.SUCCESS.setNewData(groupMessages);
    }
}